package cn.myjerry.test.DynamicCompile;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class Demo01 {
	public static void main(String[] args) throws Exception {
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
		int result = compiler.run(null, null, null, "/Users/zpon/workspace/java/testjava03/src/cn/myjerry/test/DynamicCompile/HelloWord.java");
		System.out.println(result==0?"编译成功":"编译失败");
		
		Runtime run = Runtime.getRuntime();
		Process process = run.exec("java -cp /Users/zpon/workspace/java/testjava03/src/cn/myjerry/test/DynamicCompile HelloWord");
		
		InputStream in = process.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		System.out.println(br.readLine());
		String info = "";
		while((info=br.readLine()) != null) {
			System.out.println(info);
		}
		
		
		
	}
}
